package com.hdu.clj.dncard.databaseUtil

import android.content.ContentValues
import android.content.Context
import com.hdu.clj.dncard.database.EquipmentDatabase
import com.hdu.clj.dncard.database.HeroDatabase
import com.hdu.clj.dncard.util.EquipAttr

/**
 * eid 装备id
 * attack 装备攻击力
 * defence 装备防御力
 * wisdom 装备智力加成
 * life 装备生命加成
 */
class EquipDatabaseUtil {
    fun insert(context: Context,ver:Int,equip:EquipAttr){
        val dbEuuip = EquipmentDatabase(context,"Equip",ver)
        val dbe = dbEuuip.writableDatabase
        val values = ContentValues().apply {
            put("eid",equip.eid )
            put("attack",equip.attack )
            put("defence",equip.defence )
            put("wisdom",equip.wisdom)
            put("elife",equip.elife)
            put("ename",equip.ename)
        }
        dbe.insert("Equip", null, values)
    }

    fun efind(context: Context,eid:String):Array<Int>{
        val dbEuuip = EquipmentDatabase(context,"Equip",1)
        val dbe = dbEuuip.writableDatabase
        val finde = dbe.rawQuery("select * from Equip where eid = ?", arrayOf(eid))
        var attack = 0
        var wisdom = 0
        var elife = 0
        if (finde.moveToFirst()){
            attack = finde.getInt(finde.getColumnIndex("attack"))
            wisdom = finde.getInt(finde.getColumnIndex("wisdom"))
            elife = finde.getInt(finde.getColumnIndex("elife"))
        }
        return arrayOf(attack,wisdom,elife)
    }

    fun efindname(context: Context,eid:String):String{
        val dbEuuip = EquipmentDatabase(context,"Equip",1)
        val dbe = dbEuuip.writableDatabase
        val finde = dbe.rawQuery("select * from Equip where eid = ?", arrayOf(eid))
        var name = ""

        if (finde.moveToFirst()){
            name = finde.getString(finde.getColumnIndex("ename"))
        }
        return name
    }
}